package com.inspur.system.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.inspur.common.utils.uuid.UUID;
import com.inspur.system.domain.PmBus;
import com.inspur.system.mapper.PmBusMapper;
import com.inspur.system.service.IPmBusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 模块管理 Service业务层处理
 */
@Service
public class PmBusServiceImpl implements IPmBusService {

    @Autowired
    PmBusMapper pmBusMapper;

    /**
     * 添加
     * @param pmBus
     * @return
     */
    @Override
    public int insertPmBus(PmBus pmBus) {
        String busNo="20"+UUID.generateShortUuid();
        pmBus.setBusNo(busNo);
        //TODO 同步用户表
        return pmBusMapper.insertPmBus(pmBus);
    }

    /**
     * 查询
     * @param pageNumber
     * @param pageSize
     * @param pmBus
     * @return
     */
    @Override
    public Map<String,Object> selectPmBusList(Integer pageNumber, Integer pageSize, PmBus pmBus) {
        PageHelper.startPage(pageNumber,pageSize);
        List<PmBus> pmBusList= pmBusMapper.selectPmBusList(pmBus);
        HashMap<String, Object> pmBusMap = new HashMap<>();
        PageInfo<PmBus> pmBusPageInfo = new PageInfo<>(pmBusList);
        pmBusMap.put("total",pmBusPageInfo.getTotal());
        pmBusMap.put("pmBusList",pmBusList);
        return pmBusMap;
    }

    /**
     * 删除
     * @param busNo
     * @return
     */
    @Override
    public int deletePmBus(String busNo) {
        System.out.println(busNo);
        return pmBusMapper.deletePmBus(busNo);
    }

    /**
     * 修改
     * @param pmBus
     * @return
     */
    @Override
    public String updatePmBus(PmBus pmBus) {
        String busNo = pmBus.getBusNo();
        PmBus pmBusByBusNo=null;
        if(busNo!=null){
        pmBusByBusNo= pmBusMapper.getPmBusByBusNo(busNo);
            if(pmBusByBusNo==null){
                return "数据不存在";
            }
        }
        return pmBusMapper.updatePmBus(pmBus)+"";

    }
}
